import Vue from 'vue'
import Vuex from 'vuex'
import util from './Logic/Util.js'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: {},
    token: ''
  },
  mutations: {
    resetToken: (state, payload) => {
      let res = util.decode(payload)
      console.log(res)
      if (res) {
        state.user = res
        state.token = payload
        localStorage.setItem('token', payload)
      }
    },
    clearToken: state => {
      localStorage.removeItem('token')
      state.user = {}
      state.token = ''
    }
  },
  actions: {}
})
